/**
 * jQuery minor plugins
 */



/**
 * Add text-overflow for firefox
 * usage: $(selector).ellipsis();
 */
;(function($){ $.fn.ellipsis = function(enableUpdating){
	var s = document.documentElement.style;
	if (!('textOverflow' in s || 'OTextOverflow' in s)) {
		return this.each(function(){
			var el = $(this);
			if(el.css("overflow") == "hidden"){
				var originalText = el.html(), originalTextOnly = el.text(), t = $(this.cloneNode(true)).hide().css({position:'absolute', width:'auto', overflow:'visible', maxWidth:'inherit'});
				el.after(t);
				var text = originalText;
				while(text.length > 0 && t.width() > el.width()){text = text.substr(0, text.length - 1);t.html(text + "...");}
				el.html(t.html());
				if (text!=originalText) el.attr('title', originalTextOnly);
				t.remove();
				if(enableUpdating==true){ var oldW=el.width(); setInterval(function(){ if(el.width()!=oldW){ oldW=el.width(); el.html(originalText); el.ellipsis();}}, 200); }
			}
		});
	} else return this;
};})(jQuery);




/**
 * Mini-plugin. Works only on 1 form at a time and returns an Object representation of the form, ie. { name1: value1, name2: value2 }
 */
;(function($){ $.fn.serializeForm = function(noEmpty){
	var form = $(this), arr = form.serializeArray(), obj = {}, i = 0, item;
	if (noEmpty){ for (; item=arr[i++] ;) if (typeof item.value !== 'undefined') obj[item.name] = item.value; }
	else for (; item=arr[i++] ;) obj[item.name] = item.value;
	return obj;			
};})(jQuery);


/**
 * Mini-plugin. Fills html form with data provided 
 */
;(function($){ $.fn.fillForm = function(data){
	var form=$(this),n='',f;
	for (n in data){ f=form.find('*[name="'+n+'"]'); if(f.length){if(f[0].type=='radio'||f[0].type=='checkbox')f.val([data[n]]);else f.val(data[n]);} }
	return form;
};})(jQuery);


/**
 * Mini-plugin. Properly resets html form fields 
 */
;(function($){ $.fn.resetForm = function(){
	var form=$(this);
	form.find('input:text,input[type=hidden],textarea,select').val('');
	form.find('input:radio,input:checkbox').removeAttr('checked');
	return form;
};})(jQuery);
